package top.ddandang.blog.controller;


import top.ddandang.blog.bean.GlobalResponse;
import top.ddandang.blog.service.ArticleTagsService;
import top.ddandang.blog.service.TagsService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author D
 * @since 2020-07-07
 */
@RestController
@RequestMapping("/article-tags")
public class ArticleTagsController {

    @Resource
    private ArticleTagsService articleTagsService;

    @Resource
    private TagsService tagsService;

    @PostMapping("/removeArticleTags")
    public GlobalResponse removeArticleTags(Integer articleId, Integer tagsId) {
        int flag = articleTagsService.removeArticleTags(articleId, tagsId);
        if(flag == 1) {
            //减少分类中文章的数量 异步处理
            tagsService.updateArticleAmount(tagsId, false);
            return GlobalResponse.success();
        }else {
            return GlobalResponse.failed();
        }

    }

}

